import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;

public class AppointmentManger extends JFrame {
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	public AppointmentManger() {
		setTitle("\u9884\u7EA6\u7BA1\u7406");
		getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("\u79DF\u5BA2\u7F16\u53F7");
		lblNewLabel.setBounds(85, 10, 64, 15);
		getContentPane().add(lblNewLabel);
		
		textField = new JTextField();
		textField.setBounds(172, 7, 106, 21);
		getContentPane().add(textField);
		textField.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("\u623F\u5B50\u7F16\u53F7");
		lblNewLabel_1.setBounds(85, 48, 54, 15);
		getContentPane().add(lblNewLabel_1);
		
		textField_1 = new JTextField();
		textField_1.setBounds(172, 45, 106, 21);
		getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblNewLabel_2 = new JLabel("\u9884\u7EA6\u65F6\u95F4");
		lblNewLabel_2.setBounds(85, 93, 54, 15);
		getContentPane().add(lblNewLabel_2);
		
		textField_2 = new JTextField();
		textField_2.setBounds(172, 90, 106, 21);
		getContentPane().add(textField_2);
		textField_2.setColumns(10);
		
		JButton btnNewButton = new JButton("\u9884\u7EA6");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					new Dao().insertAppoinment(textField.getText(), textField_1.getText(), textField_2.getText());
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		btnNewButton.setBounds(85, 132, 93, 23);
		getContentPane().add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("\u53D6\u6D88\u9884\u7EA6");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					new Dao().deleteAppoinment(textField_1.getText(), textField_2.getText());
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		btnNewButton_1.setBounds(185, 132, 93, 23);
		getContentPane().add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("\u4FEE\u6539\u72B6\u6001");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					new Dao().updateAppoinment(textField.getText(), textField_1.getText());
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		btnNewButton_2.setBounds(85, 180, 93, 23);
		getContentPane().add(btnNewButton_2);
		
		JButton button = new JButton("\u67E5\u8BE2\u65F6\u95F4");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					ResultSet result=new Dao().selectAppoinment(textField.getText(), textField_1.getText());
					result.first();
					//textField_1.setText(result.getString(3));
					textField_2.setText(result.getString(4));
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		this.setSize(500, 300);
		button.setBounds(188, 180, 93, 23);
		getContentPane().add(button);
	}

}
